<table cellspacing="0" cellpadding="0" class="nowrap">
<tr>
	<th><?=T_('Sort By:')?>&nbsp;&nbsp;&nbsp;&nbsp;</th>
	<th>
		<?= form_dropdown('order', $orderOptions, $this->input->get_post('order'), sprintf('class="selective_small" id="select_order" __templateUrl="%s"', Xregenerate_url('order,direction'))) ?>
		<div class="hidden">
			<?= form_dropdown('direction', array('asc' => T_("Up"), 'desc' => T_("Down")), $this->input->get_post('direction'), 'class="selective_small" id="select_direction"') ?>
		</div>
	</th>
</tr>
</table>

<script>
//order for brands, cats, etc
$(document).ready(function() {
	var currentOrder = $('#select_order').val();
	var currentDirection = $('#select_direction').val();

	//bind event
	$('#select_order').bind('change', function() {
		var $this = $(this);
		var newOrder = $this.val();
		var templateUrl = $this.attr('__templateUrl');
	
		if (templateUrl.toString().indexOf('?') >= 0)
		{
			templateUrl += '&';
		}
		else
		{
			templateUrl += '?';
		}

		var direction = '';
		
		if (newOrder == currentOrder && currentDirection == 'asc')
		{
			direction += '&direction=desc';
		}
		else
		{
			direction += '&direction=asc';
		}

		window.location = templateUrl + 'order=' + newOrder + direction;
	});
});
</script>
